import { useState, useEffect } from "react";
import CommonModal from "@/components/CommonModal";
import ProTable from '@/components/ProTable';
import { Select, Form, Button, Modal } from "antd";
import { uniqueCodeLog } from '../service.js';

const UniqueCodeLog = ({ row, handleCancel  }) => {

	const [open, setOpen] = useState(false);

	const [logList, setLogList] = useState([]);

	useEffect(() => {
		setOpen(true);
		queryLog();
	}, [])

	//获取唯一码日志记录
	const queryLog = async () => {
		START_LOADING();
		const { success, data } = await uniqueCodeLog({
			businessType: 'unique-code-log',
			uniqueCode: row.code
		})
		if (success) {
			setLogList(data.records);
		}
		END_LOADING();
	}

	const onCancel = () => {
		setOpen(false);
	}

	const afterClose = () => {
		handleCancel();
	}

	const columns = [
		{
			name: '操作人账号',
			code: 'operator',
			width: 100
		},
		{
			name: '操作界面',
			code: 'subType',
			width: 100
		},
		{
			name: '操作类型',
			code: 'type',
			width: 100
		},
		{
			name: '操作事件',
			code: 'action',
			width: 240
		},
		{
			name: '操作时间',
			code: 'createTime',
			width: 120
		},
	]

	const ProTableProps = {
		data: logList,
		columns
	}

	return (
		<CommonModal
			title="唯一码日志"
			open={open}
			width="920px"
			onCancel={onCancel}
			afterClose={afterClose}
			footer={<Button onClick={onCancel}>关闭</Button>}
		>
			<ProTable { ...ProTableProps } />
		</CommonModal>
	);
};

export default UniqueCodeLog;
